package com.tvsinfo.jdk.demo.case6_higher_order_function.order;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum OrderStatusEnum {
    TODO(101, 0, "todo", "未处理"),
    NOT_VALID(102, 102, "todo", "订单未生效"),
    TO_CONFIRM(103, 20, "toConfirm", "待接单"),

    CONFIRMED(201, 1, "confirmed", "已接单"),
    PART_USED(202, 202, "partUsed", "部分使用"),
    WAIT_FINISH(203,203,"waitFinish","待完成"),
    WAIT_DELIVERY(204,8,"waitDelivery","待发货"),
    FINISHED(301, 2, "finished", "已完成"),

    CANCELLED(401, 3, "cancelled", "已取消-C端"),
    CANCELLED_SYS(402, 3, "cancelledSys", "已取消-System"),

    INVALID(403, 5, "invalid", "已取消-B端(作废)"),
    REFUSED(404, 4, "refused", "已取消-B端(拒绝)"),
    EXPIRED(405, 7, "expired", "已取消-过期"),

    TIMEOUT_VALID(406, 9, "timeoutValid", "已超时(未作废)"),
    CANCEL_VALID(407, 10, "cancelValid", "已取消(未作废)"),

    LOCKED(501, 501, "locked", "已锁定"),
    DEDUCT_RIGHTS_FAILED(601, 601, "deductRightsFailed", "扣款失败"),
    ;

    private Integer key;
    private Integer oldKey;
    private String desc;
    private String cnDesc;
    OrderStatusEnum(Integer key, Integer oldKey, String desc, String cnDesc) {
        this.key = key;
        this.oldKey = oldKey;
        this.desc = desc;
        this.cnDesc = cnDesc;
    }

    private static final Map<Integer, List<OrderStatusEnum>> oldOrderStatusEnumMap = new HashMap<>();
    static {
        OrderStatusEnum[] arr$ = values();
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; ++i$) {
            OrderStatusEnum orderStatus = arr$[i$];
            List<OrderStatusEnum> orderStatusEnums = oldOrderStatusEnumMap.get(orderStatus.oldKey);
            if (null == orderStatusEnums) {
                orderStatusEnums = new ArrayList<>();
                oldOrderStatusEnumMap.put(orderStatus.oldKey, orderStatusEnums);
            }
            orderStatusEnums.add(orderStatus);
        }
    }

    /**
     * 通过老的key获取
     * create by Ruyi.Song on 2018/8/16 15:51
     */
    public static List<OrderStatusEnum> getByOldKey(Integer oldKey) {
        if (null == oldKey) {
            return null;
        }
        List<OrderStatusEnum> orderStatusEnums = oldOrderStatusEnumMap.get(oldKey);
        return orderStatusEnums;
    }

    public Integer getKey() {
        return this.key;
    }
}
